#!perl

use 5.016;

my $sample_file = $ARGV[0];
open(my $fh, '<', $sample_file);
while (my $line = <$fh>) {
    chomp $line;
    $line =~ s/^\s+|\s+$//g;
    if ($line =~ /^(.*?\{.*?)(\d+):([^{]+)\}$/) {
        say $1 . '}';
        output_split_str($2, $3);
    }
}

sub output_split_str {
    my ($first, $str) = @_;
    if ($str =~ /^(.*?)(\d+):(.*?)$/) {
        say "set_bit{$first}{$1}";
        output_split_str($2, $3);
    }
    else {
        say "set_bit{$first}{$str}";
    }
}


